(function(window, undefined) {

    let t = null

    $.fn.lazyLoad = function() {

        let _this = this
        
        function lazyLoad() {

            if (t) clearTimeout(t)
            t = setTimeout(() => {
                let windowH = window.innerHeight || document.documentElement.clientHeight
                let scrollH = document.body.scrollTop || document.documentElement.scrollTop
                let showH = windowH + scrollH
            
                let imgs = _this
            
                for (let i=0; i<imgs.length; i++) {
            
                    if (imgs[i].offsetTop < showH) {
                        imgs[i].src = imgs[i].getAttribute('data-src')
                    }
                }
            }, 100);
        }
        
        lazyLoad()
        window.onscroll = lazyLoad
    }
    
})(window)

